<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_category
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
$loai 		= $params->get('loai',	1);
$catid 		= $params->get('catid',  '');
$db = & JFactory::getDBO();
if($loai==1){
	$sql="SELECT * from #__content where catid='".$catid[0]."' and state=1 order by publish_up desc limit 0,3";
	$db->setQuery($sql);
	$rows = $db->loadObjectList();
?>
<div class="wmcnews">
	<h2><strong><?php echo JText::_('Recent News');?></strong></h2>
	<div id="home-blog-list">
    <?php
    foreach ($rows as $item) :
		$image_intro = $item->images;
		$image_intro = explode('","',$image_intro);
		$image_intro = explode('":"',$image_intro[0]);
		$image_intro = str_replace('\/','/',$image_intro[1]);
		
		$linkitem = 'index.php?option=com_content&view=article&id='.$item->id.':'.$item->alias.'&catid='.$item->catid.'&Itemid=109';
	?>
		<div class="home-post clearfix">
			<!--<div class="home-post-img">
				<a href="<?php echo $linkitem;?>"><img src="<?php echo $image_intro;?>" title="<?php echo $item->title;?>" /></a>
			</div>-->
			<div class="home-post-content">
				<h5><a href="<?php echo $linkitem;?>"><?php echo $item->title;?></a></h5>
				<span class="datepublish"><?php echo date('jS M, Y', strtotime($item->publish_up)); ?></span>
				<!--<span><?php echo $item->introtext;?></span>-->
			</div>
		</div>
    <?php 
	endforeach; 
	?>
	</div>
</div>
<?php
}
if($loai==2){
?>
<div class="jobposting">
    <h3><strong><?php echo JText::_('Loyalty Program');?></strong></h3>
    <div id="testimonials-widget-1" class="widget-testimonials-scroll">
    <?php
	foreach ($list as $item) :
	?>
        <div class="wtestimonial-item">
            <div class="wtestimonial-content">
            	<!--<a href="<?php echo $item->link; ?>">--><?php echo $item->displayIntrotext;?><!--</a>-->
            </div>
        </div>
    <?php 
	endforeach; 
	?>
    </div>
    <div id="testimonials-widget-1-prev" class="portfolio-widget-prev"></div>
    <div id="testimonials-widget-1-next" class="portfolio-widget-next"></div>
    <script type="text/javascript">
    jQuery("#testimonials-widget-1").carouFredSel({
        circular:true,
        responsive:true,
        auto:false,
        items:1,
        scroll:{
            items:"page",
            fx:"fade",
            duration:300,
            wipe:true
        },
        prev:{
            button:"#testimonials-widget-1-prev",
            key:"left"
        },
        next:{
            button:"#testimonials-widget-1-next",
            key:"right"
        }
    });
    </script>

</div>
<?php
}
if($loai==0){
?>
<ul class="category-module<?php echo $moduleclass_sfx; ?>">
<?php if ($grouped) : ?>
	<?php foreach ($list as $group_name => $group) : ?>
	<li>
		<h<?php echo $item_heading; ?>><?php echo $group_name; ?></h><?php echo $item_heading; ?>>
		<ul>
			<?php foreach ($group as $item) : ?>
				<li>
					<h<?php echo $item_heading + 1; ?>>
					   	<?php if ($params->get('link_titles') == 1) : ?>
						<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
						<?php echo $item->title; ?>
				        <?php if ($item->displayHits) :?>
							<span class="mod-articles-category-hits">
				            (<?php echo $item->displayHits; ?>)  </span>
				        <?php endif; ?></a>
				        <?php else :?>
				        <?php echo $item->title; ?>
				        	<?php if ($item->displayHits) :?>
							<span class="mod-articles-category-hits">
				            (<?php echo $item->displayHits; ?>)  </span>
				        <?php endif; ?></a>
				            <?php endif; ?>
			        </h><?php echo $item_heading + 1; ?>>


				<?php if ($params->get('show_author')) :?>
					<span class="mod-articles-category-writtenby">
					<?php echo $item->displayAuthorName; ?>
					</span>
				<?php endif;?>

				<?php if ($item->displayCategoryTitle) :?>
					<span class="mod-articles-category-category">
					(<?php echo $item->displayCategoryTitle; ?>)
					</span>
				<?php endif; ?>
				<?php if ($item->displayDate) : ?>
					<span class="mod-articles-category-date"><?php echo $item->displayDate; ?></span>
				<?php endif; ?>
				<?php if ($params->get('show_introtext')) :?>
			<p class="mod-articles-category-introtext">
			<?php echo $item->displayIntrotext; ?>
			</p>
		<?php endif; ?>

		<?php if ($params->get('show_readmore')) :?>
			<p class="mod-articles-category-readmore">
				<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
				<?php if ($item->params->get('access-view') == false) :
						echo JText::_('MOD_ARTICLES_CATEGORY_REGISTER_TO_READ_MORE');
					elseif ($readmore = $item->alternative_readmore) :
						echo $readmore;
						echo JHtml::_('string.truncate', $item->title, $params->get('readmore_limit'));
						if ($params->get('show_readmore_title', 0) != 0) :
							echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
						endif;
					elseif ($params->get('show_readmore_title', 0) == 0) :
						echo JText::sprintf('MOD_ARTICLES_CATEGORY_READ_MORE_TITLE');
					else :

						echo JText::_('MOD_ARTICLES_CATEGORY_READ_MORE');
						echo JHtml::_('string.truncate', ($item->title), $params->get('readmore_limit'));
					endif; ?>
	        </a>
			</p>
			<?php endif; ?>
		</li>
			<?php endforeach; ?>
		</ul>
	</li>
	<?php endforeach; ?>
<?php else : ?>
	<?php foreach ($list as $item) : ?>
	    <li>
	   	<h<?php echo $item_heading; ?>>
	   	<?php if ($params->get('link_titles') == 1) : ?>
		<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
		<?php echo $item->title; ?>
        <?php if ($item->displayHits) :?>
			<span class="mod-articles-category-hits">
            (<?php echo $item->displayHits; ?>)  </span>
        <?php endif; ?></a>
        <?php else :?>
        <?php echo $item->title; ?>
        	<?php if ($item->displayHits) :?>
			<span class="mod-articles-category-hits">
            (<?php echo $item->displayHits; ?>)  </span>
        <?php endif; ?></a>
            <?php endif; ?>
        </h><?php echo $item_heading; ?>>

       	<?php if ($params->get('show_author')) :?>
       		<span class="mod-articles-category-writtenby">
			<?php echo $item->displayAuthorName; ?>
			</span>
		<?php endif;?>
		<?php if ($item->displayCategoryTitle) :?>
			<span class="mod-articles-category-category">
			(<?php echo $item->displayCategoryTitle; ?>)
			</span>
		<?php endif; ?>
        <?php if ($item->displayDate) : ?>
			<span class="mod-articles-category-date"><?php echo $item->displayDate; ?></span>
		<?php endif; ?>
		<?php if ($params->get('show_introtext')) :?>
			<p class="mod-articles-category-introtext">
			<?php echo $item->displayIntrotext; ?>
			</p>
		<?php endif; ?>

		<?php if ($params->get('show_readmore')) :?>
			<p class="mod-articles-category-readmore">
				<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
		        <?php if ($item->params->get('access-view') == false) :
						echo JText::_('MOD_ARTICLES_CATEGORY_REGISTER_TO_READ_MORE');
					elseif ($readmore = $item->alternative_readmore) :
						echo $readmore;
						echo JHtml::_('string.truncate', $item->title, $params->get('readmore_limit'));
					elseif ($params->get('show_readmore_title', 0) == 0) :
						echo JText::sprintf('MOD_ARTICLES_CATEGORY_READ_MORE_TITLE');
					else :
						echo JText::_('MOD_ARTICLES_CATEGORY_READ_MORE');
						echo JHtml::_('string.truncate', $item->title, $params->get('readmore_limit'));
					endif; ?>
	        </a>
			</p>
		<?php endif; ?>
	</li>
	<?php endforeach; ?>
<?php endif; ?>
</ul>
<?php
}

?>
